FROM ubuntu:24.04

# 这是一个为C/C++提供开发环境的Docker镜像，并使用zsh终端

RUN apt-get update -y && DEBIAN_FRONTEND=noninteractive apt install -y \
	build-essential zsh eza \
	git cmake make gdb clang-format \
	dos2unix tree unzip\
	automake sed rsync wget vim curl \
	&& apt-get clean && rm -rf /var/lib/apt/lists/*

RUN sed -i 's/required/sufficient/g' /etc/pam.d/chsh && echo 'root:admin'| chpasswd;sed -i 's:/bin/sh:/bin/zsh:' /etc/passwd ;

ENV USER=systech
ENV SHELL=/bin/zsh
ARG USER_ID=0
ARG GROUP_ID=0
# RUN groupadd -g ${GROUP_ID} chengyh-docker && useradd -m -g chengyh-docker -u ${USER_ID} systech && usermod -s /bin/zsh systech

RUN set -eux; \
     # 检查GID是否已存在，如果存在则使用已存在的组，否则创建新组
     if ! getent group $GROUP_ID > /dev/null; then \
         groupadd -g $GROUP_ID chengyh-docker; \
     else \
         # 如果存在，我们使用已存在的组，但需要知道组名
         existing_group_name=$(getent group $GROUP_ID | cut -d: -f1); \
         groupmod -n chengyh-docker $existing_group_name; \
     fi && \
     # 同样，检查用户ID是否存在
     if ! getent passwd $USER_ID > /dev/null; then \
         useradd -m -g $GROUP_ID -u $USER_ID systech; \
     else \
         # 如果用户ID存在，我们修改该用户的用户名和组（这通常不安全，不推荐）
         existing_user_name=$(getent passwd $USER_ID | cut -d: -f1); \
         usermod -l systech -g chengyh-docker -m -d /home/systech $existing_user_name; \
     fi

USER systech

# 修改 /etc/passwd 文件，为所有用户设置默认的 shell 为 /bin/zsh
RUN sh -c "$(curl -fsSL https://gitee.com/mirrors/oh-my-zsh/raw/master/tools/install.sh)"; \
	git clone --depth=1 https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions && rm -rf ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions/.git;\
	git clone --depth=1 https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting && rm -rf ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting/.git;\
	git clone --depth=1 https://github.com/zdharma-continuum/fast-syntax-highlighting.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/fast-syntax-highlighting && rm -rf ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/fast-syntax-highlighting/.git;\
	git clone --depth=1 https://github.com/romkatv/powerlevel10k ~/.oh-my-zsh/custom/themes/powerlevel10k && rm -rf ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k/.git;\
	git clone --depth=1 https://github.com/DarrinTisdale/zsh-aliases-exa.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-aliases-eza && rm -rf ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-aliases-eza/.git

WORKDIR /home/systech/workspace

COPY .zshrc /home/systech/
